﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Data;

public partial class Web_receveid : System.Web.UI.Page
{
  
    protected void Page_Load(object sender, EventArgs e)
    {
        Session["current"] = "Recieved Purchase Order";//current page

        if (Request.QueryString["a"] != null)//updateed data message
        {
            ASPxLabel2.Visible = true;
            ASPxLabel2.Text = "You have succesfully updated your purchase order";
        }
        
        if (Session["user"] != null)//check user
         {
         string user = Session["user"].ToString();
          if (user == "viewer")
         {
         Response.Redirect("index.aspx");
           }

          }
           else
           {
           Response.Redirect("index.aspx");
           }
            
        
    }

    protected void ASPxRadioButton2_CheckedChanged(object sender, EventArgs e)
    {
        //ASPxLabel4.Visible = true;
        //DropDownList1.Visible = false;
        //ASPxLabel3.Visible = false;
        //DropDownList1.Visible = false;
    }

    protected void ASPxRadioButton1_CheckedChanged(object sender, EventArgs e)
    {
        //ASPxLabel3.Visible = true;
        //DropDownList1.Visible = false;
        //ASPxLabel4.Visible = false;
        //DropDownList1.Visible = false;
    }

    protected void DropDownList1_SelectedIndexChanged(object sender, EventArgs e)
    {

       
    }

    protected void ASPxGridView1_CustomUnboundColumnData(object sender, DevExpress.Web.ASPxGridView.ASPxGridViewColumnDataEventArgs e)
    {
        try
        {
            if (e.Column.FieldName == "Total" && e.IsGetData)
            {

                decimal price = Convert.ToDecimal(e.GetListSourceFieldValue("Pur_Price"));
                decimal qty = Convert.ToDecimal(e.GetListSourceFieldValue("Qty"));
                e.Value = price * qty;

            }
        }
        catch
        {
            Response.Redirect("404.ASPX");
        }
    }//calculate total

    #region upadate
    protected void ASPxButton1_Click(object sender, EventArgs e)
    {
       
        string user = Session["username"].ToString();

            Bestlife.ERP.Entities.E_recevedstock stock = new Bestlife.ERP.Entities.E_recevedstock();

            stock.Orid = DropDownList1.Text;
           
                List<Object> itemid = ASPxGridView1.GetSelectedFieldValues("Qty");
                if (itemid.Count == 0)
                {
                    ASPxLabel4.Visible = true;
                    ASPxLabel4.Text = "Please select products ";
                }
                else
                {
                    foreach (object selectitemid in itemid)
                    {
                        stock.Qty = decimal.Parse(selectitemid.ToString());
                    }
                    
                    List<Object> selectItems = ASPxGridView1.GetSelectedFieldValues("Pro_Name");
                    foreach (object selectItemId in selectItems)
                    {

                        stock.Proname = selectItemId.ToString();
                    }

                    stock.Status = ASPxComboBox1.Text;
                    string status = stock.Status;

                    Bestlife.ERP.BusinessRules.B_receivedstock.setstock(stock, user);
                    ASPxLabel4.Visible = false;
                    Response.Redirect("receveid.aspx?a=2");
                }
            
        }
       
        
    
    #endregion

    protected void ASPxGridView1_RowUpdating(object sender, DevExpress.Web.Data.ASPxDataUpdatingEventArgs e)
    {

    }

    protected void ASPxGridView1_SelectionChanged(object sender, EventArgs e)
    {
        //try{
        

        //    ASPxGridView1.Selection.SetSelectionByKey("Pro_Name", true);
        //}
        //catch
        //{
        //    Response.Redirect("404.ASPX");
        //}

    }//row selection
 
   
}